package org.six11.ss.server;

import java.io.PrintWriter;

import org.six11.ss.server.bean.Person;
import org.six11.ss.server.bean.Room;
import org.six11.ss.shared.Message;
import org.six11.util.adt.MultiState;

/**
 * 
 *
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class NickHandler extends AppletMessageHandler {

  /**
   * @param state
   */
  public NickHandler(MultiState state) {
    super(state);
  }

  /**
   * 
   */
  @Override
  public void handle(Message m, String sessionID, PrintWriter out) {
    Person person = getPersonBySession(sessionID);
    String oldNick = person.getNick();
    String newNick = m.getParam("newNick");
    person.setNick(newNick);
    Message msg = new Message("chat");
    msg.addParam("content", oldNick + " is now known as " + person.getNick());
    msg.addParam("from", "Stellasketch");
    Room room = person.getRoom();
    RoomHandler rh = (RoomHandler) getHandler("room");
    rh.sendMessageToAll(msg, room);
  }

}
